//
//  RecommenView.m
//  礼物
//
//  Created by dllo on 15/11/11.
//  Copyright © 2015年 liangsicheng. All rights reserved.
//

#import "RecommenView.h"

@implementation RecommenView
-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self createSubview];
    }
    return self;
}
-(void)createSubview
{
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc]init];
    self.myRecommenCollectionView=[[RecommenCollectionView alloc]initWithFrame:MAINSCREEN collectionViewLayout:flowLayout];
    
    flowLayout.itemSize=CGSizeMake(180*WIDTH/375, 250*HEIGHT/667);
    flowLayout.minimumInteritemSpacing=2;
    flowLayout.sectionInset=UIEdgeInsetsMake(5*HEIGHT/667, 5*WIDTH/375, 5*HEIGHT/667, 5*WIDTH/375);
    self.myRecommenCollectionView.showsVerticalScrollIndicator=NO;
    self.myRecommenCollectionView.delegate=self;
    self.myRecommenCollectionView.dataSource=self;
    [self addSubview:self.myRecommenCollectionView];
    self.myRecommenCollectionView.backgroundColor=[UIColor colorWithWhite:1.000 alpha:0.940];
    [self.myRecommenCollectionView registerClass:[RecommenCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.recommenCellArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    RecommenCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.backgroundColor=[UIColor whiteColor];
    RecommenModel *model=[self.recommenCellArray objectAtIndex:indexPath.row];
    
    [cell setModel:model];
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    RecommenModel *model=[self.recommenCellArray objectAtIndex:indexPath.item];
    [self.delegate pushDetailViewController:model];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
